# -*- coding:utf-8 -*-
from django.db import models

# Create your models here.
class AGBrand(models.Model):
    ''' 品牌表 '''
    
    brand_id = models.AutoField(primary_key=True)
    brand_name = models.CharField(max_length=255)
    add_time = models.DateField(auto_now_add=True)
    
    def __unicode__(self):
        return self.brand_name
    
    class Meta:
        db_table = u'ag_car_brand'
        
        def __unicode__(self):
            return '品牌表'

class AGFactory(models.Model):
    ''' 厂商表 '''
    
    factory_id = models.AutoField(primary_key=True)
    brand_id = models.IntegerField(null=False, blank=False)
    factory_name = models.CharField(max_length=255)
    
    def __unicode__(self):
        return self.factory_name
    
    class Meta:
        db_table = u'ag_car_factory'

class AGCarSeries(models.Model):
    ''' 车系表 '''
    
    series_id = models.AutoField(primary_key=True)
    factory_id = models.IntegerField(null=False, blank=False)
    series_name = models.CharField(max_length=255)
    # 年代
    car_year = models.CharField(max_length=255)
    
    def __unicode__(self):
        return self.series_name
    
    class Meta:
        db_table = u'ag_car_series'
        
        def __unicode__(self):
            return u'car series'
    

class AGCarStyle(models.Model):
    ''' 车型表 '''
    
    car_style_id = models.AutoField(primary_key=True)
    series_id = models.IntegerField(null=False, blank=False)
    car_style_name = models.CharField(max_length=255)
    # 年代，如2011款
    first_care_mile = models.IntegerField(null=True, blank=True)
    care_interval = models.IntegerField(null=True, blank=True)
    
    def __unicode__(self):
        return self.car_style_name
    
    class Meta:
        db_table = u'ag_car_style'
    
class AGParts(models.Model):
    ''' 配件表 '''
    
    parts_id = models.AutoField(primary_key=True)
    parts_name = models.CharField(max_length=128)
    parts_price = models.FloatField()
    class Meta:
        db_table = u'ag_parts'

class AGCareDetail(models.Model):
    ''' 维修明细表 '''
    
    care_detail_id = models.AutoField(primary_key=True)
#    parts_id = models.IntegerField()
#    miles = models.IntegerField()

    # 临时修改
    car_style_name = models.CharField(max_length=255)
    parts_name = models.CharField(max_length=255)
    parts_price = models.FloatField()
    care_miles = models.IntegerField()
    class Meta:
        db_table = u'ag_care_detail'

class AGSupplier(models.Model):
    ''' 供应商表 '''
    
    supplier_id = models.AutoField(primary_key=True)
    # 品牌
    brand_name = models.CharField(max_length=255)
    # 供应商名称 
    supplier_name = models.CharField(max_length=255)
    # 供应商电话 
    supplier_phone = models.CharField(max_length=255)
    # 供应商地址
    supplier_address = models.CharField(max_length=255)

    def __unicode__(self):
        return self.supplier_name

    class Meta:
        db_table = u'ag_supplier'
        def __unicode__(self):
            return u'supplier_table';

class AGInsurance(models.Model):
    ''' 保险表 '''
    
    insurance_id = models.AutoField(primary_key=True)
    insurance_company = models.CharField(max_length=255)
    # 类型，中资1，外资2
    insurance_type = models.IntegerField()
    # 地区，暂时用简拼，bj
    area = models.CharField(max_length=36)
    # 金额
    amount = models.FloatField(blank=True, null=True)
    
    def __unicode__(self):
        return self.insurance_company
    
    class Meta:
        db_table = 'ag_insurance'
        def __unicode__(self):
            return u'保险表'
        
    
